{extend name="base:base" /}
{block name="body"}
<div class="layui-btn-group">
    <a class="layui-btn a_load layui-btn-small layui-btn-normal" href="{:Url::build('Category/add')}">增加</a>
</div>

<div class="layui-form">
    <div class="category">
        <div class="hd cf">
            <div class="fold">折叠</div>
            <div class="order">排序</div>
            <div class="order">标识</div>
            <div class="order">发布</div>
            <div class="name">名称</div>
        </div>
        {:App::action('tree',[$tree])}
    </div>
</div>
{/block}
{block name="css"}
<link href="__CSS__/category.css" rel="stylesheet">
{/block}
{block name="script"}
<script type="text/javascript">
    UrlHighlight("{:Url::build('Category/index')}");
    layui.use(['jquery', 'form'], function () {
        /* 分类展开收起 */
        layui.$(".category dd").prev().find(".fold i").addClass("icon-unfold").click(function () {
            var self = layui.$(this);
            if (self.hasClass("icon-unfold")) {
                self.closest("dt").next().slideUp("fast", function () {
                    self.removeClass("icon-unfold").addClass("icon-fold");
                });
            } else {
                self.closest("dt").next().slideDown("fast", function () {
                    self.removeClass("icon-fold").addClass("icon-unfold");
                });
            }
        });

        /* 三级分类删除新增按钮 */
        layui.$(".category dd dd .add-sub").remove();

        /* 实时更新分类信息 */
        layui.$(".category").on("submit", "form", function () {
            var self = layui.$(this);
            layui.$.post(self.attr("action"), self.serialize(), function (data) {
                var name = data.code==1 ? "success" : "error", msg;
                /* 提示信息 */
                layui.layer.msg(data.msg);
            }, "json");
            return false;
        }).on("focus", "input", function () {
            layui.$(this).data('param', layui.$(this).closest("form").serialize());
        }).on("blur", "input", function () {
            if (layui.$(this).data('param') != layui.$(this).closest("form").serialize()) {
                layui.$(this).closest("form").submit();
            }
        });

        layui.$(".move").on('click', function () {
            var url = layui.$(this).attr('href');
            layui.$.get(url, function (str) {
                if (str.code === 0) {
                    return  alert_msg(str.msg);
                }
                layui.layer.open({
                    type: 1,
                    title: "移动分类",
                    area: ['420px','400px'],
                    content: str
                });
            });
            return false;
        });

    });
</script>

{/block}